package router

import (
	"HeadLineNews/controller/app/comment"
	"HeadLineNews/controller/app/user"
	"HeadLineNews/controller/app/user_news"
	"HeadLineNews/controller/app/vote"
	"HeadLineNews/controller/manage/admin"
	"HeadLineNews/controller/manage/author"
	"HeadLineNews/controller/manage/category"
	"HeadLineNews/controller/manage/news"
	"HeadLineNews/controller/manage/permission"
	"HeadLineNews/utils/middlewares"
)

// activeManageAdminServer admin 路由
func activeManageAdminServer(r *Router) {
	server := admin.NewServer()
	r = r.Group("admin/")
	r.POST("login/", "管理员登录", server.LoginHandler)
	ra := r.Group("", middlewares.AdminLoginRequired, middlewares.PermissionRequired)
	ra.POST("register/", "管理员注册", server.RegisterHandler)
	ra.POST("list/", "管理员列表", server.ListAdminHandler)

}

// activeManageAuthorServer 作者相关路由
func activeManageAuthorServer(r *Router) {
	server := author.NewServer()
	ra := r.Group("admin/author/", middlewares.AdminLoginRequired, middlewares.PermissionRequired)
	ra.POST("add/", "新增作者", server.AddAuthorHandler)
	ra.POST("update/", "更新作者", server.UpdateAuthorHandler)
	ra.GET("retrieve/:authorId/", "检索作者", server.RetrieveAuthorHandler)
	ra.POST("list/", "展示作者", server.ListAuthorHandler)
	ra.GET("delete/:authorId/", "删除作者", server.DeleteAuthorHandler)
}

// activeManageCategoryServer 分类相关路由
func activeManageCategoryServer(r *Router) {
	server := category.NewServer()
	ra := r.Group("admin/category/", middlewares.AdminLoginRequired, middlewares.PermissionRequired)
	ra.POST("add/", "新增分类", server.AddCategoryHandler)
	ra.POST("update/", "更新分类", server.UpdateCategoryHandler)
	ra.GET("retrieve/:categoryId/", "检索分类", server.RetrieveCategoryHandler)
	ra.POST("list/", "展示分类", server.ListCategoryHandler)
}

// activeManageNewsServer 新闻相关路由
func activeManageNewsServer(r *Router) {
	server := news.NewServer()
	ra := r.Group("admin/news/", middlewares.AdminLoginRequired, middlewares.PermissionRequired)
	ra.POST("add/", "新增新闻", server.AddNewsHandler)
	ra.POST("update/", "更新新闻", server.UpdateNewsHandler)
	ra.GET("retrieve/:newsId/", "检索新闻", server.RetrieveNewsHandler)
	ra.POST("list/", "搜索新闻", server.ListNewsHandler)
}

// activeManagePermissionServer 权限控制相关路由
func activeManagePermissionServer(r *Router) {
	server := permission.NewServer()
	ra := r.Group("admin/perm/", middlewares.AdminLoginRequired, middlewares.PermissionRequired)
	ra.POST("list/", "展示权限", server.ListPermsHandler)
	ra.GET("flush/", "刷新权限", server.FlushPermsHandler)

	ra.POST("group/add/", "新增群组", server.AddGroupHandler)
	ra.GET("group/delete/:groupId/", "删除群组", server.DeleteGroupHandler)
	ra.POST("group/list/", "展示群组", server.ListGroupHandler)

	ra.POST("group/perms/add/", "添加群组权限", server.AddPermsToGroupHandler)
	ra.POST("group/perms/update/", "更新群组权限", server.UpdatePermsToGroupHandler)
	ra.POST("group/perms/list/", "展示群组权限", server.ListGroupPermsHandler)

	ra.POST("group/admin/add/", "添加群组管理员", server.AddAdminsToGroupHandler)
	ra.POST("group/admin/update/", "更新群组管理员", server.UpdateAdminsToGroupHandler)
	ra.POST("group/admin/list/", "展示群组管理员", server.ListGroupAdminsHandler)
}

// activeAppUserServer user 路由
func activeAppUserServer(r *Router) {
	server := user.NewServer()
	r = r.Group("user/")
	r.POST("login/", "用户登录", server.UserLoginHandler)
	r.POST("register/", "用户注册", server.UserRegisterHandler)
}

// activeAppUserCommentServer 用户评论
func activeAppUserCommentServer(r *Router) {
	server := comment.NewServer()
	ru := r.Group("app/comment/", middlewares.UserLoginRequired)
	ru.POST("add/", "新增评论", server.AddCommentHandler)
	ru.POST("list/", "检索新闻评论", server.RetrieveNewsCommentHandler)
	ru.POST("floor/list/", "检索新闻楼层评论", server.RetrieveNewsFloorCommentHandler)
}

// activeAppUserVoteServer 用户点赞
func activeAppUserVoteServer(r *Router) {
	server := vote.NewServer()
	ru := r.Group("app/user/", middlewares.UserLoginRequired)
	ru.POST("vote/", "用户点赞", server.UserVoteHandler)
}

// activeAppUserNewsServer 用户查看新闻
func activeAppUserNewsServer(r *Router) {
	server := user_news.NewServer()
	ru := r.Group("app/user/", middlewares.UserLoginRequired)
	ru.GET("news/retrieve/:newsId/", "用户检索新闻", server.UserRetrieveNewsHandler)
	ru.POST("news/list/", "用户新闻列表", server.UserListNewsHandler)
}
